package com.jp.fm.dao;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.jp.fm.TestHelper;
import com.jp.fm.data.Account;
import com.jp.fm.data.BillReminder;

public class BillReminderDaoTest {

	private BillReminderDao billReminderDao = null;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		TestHelper.setupTestDb();

		billReminderDao = new BillReminderDao();
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public final void testFindByDueDateAndRange() {

		List<BillReminder> ret = billReminderDao.findByDueDateAndRange(31);
		assertNotNull(ret);
		assertEquals(1, ret.size());
	}

	@Test
	public final void testFindAll() {

		List<BillReminder> ret = billReminderDao.findAll();
		assertNotNull(ret);
		assertEquals(1, ret.size());
	}

	@Test
	public final void testWriteObject() {

		BillReminder billReminder = new BillReminder(null, "test1",
				Float.valueOf("100.99"), new Account(null, "Visa Card", null,
						null, null, null, 0), new Date(), "Monthly");

		Integer ret = billReminderDao.writeObject(billReminder);
		assertNotNull(ret);
	}

	@Test
	public final void testDelete() {

		BillReminder billReminder = new BillReminder(null, "test1",
				Float.valueOf("100.99"), new Account(null, "Visa Card", null,
						null, null, null, 0), new Date(), "Monthly");

		Integer ret = billReminderDao.writeObject(billReminder);
		assertNotNull(ret);
		billReminder.setId(ret);
		billReminderDao.delete(billReminder);
	}

}
